<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8" />
	<title>书店管理系统</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" type="text/css" href="/public/css/bootstrap.min.css" />
	<link rel="stylesheet" type="text/css" href="/public/css/swiper.min.css" />
	<link href="http://cdn.bootcss.com/animate.css/3.5.2/animate.min.css" rel="stylesheet" media="all">
	<link href="/public/css/bootstrap-touch-slider.css" rel="stylesheet" media="all">
	<link rel="stylesheet" type="text/css" href="/public/css/pc.css" />
	<link rel="stylesheet" type="text/css" media="screen and (max-width:1200px)" href="/public/css/ipad.css">
	<link rel="stylesheet" type="text/css" media="screen and (max-width:768px)" href="/public/css/phone.css">
	<script type="text/javascript" src="/public/js/jquery-1.11.1.min.js"></script>
	<script type="text/javascript" src="/public/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="/public/js/swiper.min.js"></script>
	<script type="text/javascript" src="/public/js/scrollReveal.js"></script>
	<script src="http://cdn.bootcss.com/jquery.touchswipe/1.6.18/jquery.touchSwipe.min.js"></script>
	<script src="/public/js/bootstrap-touch-slider-min.js"></script>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=Diy1GpUowSnG4kyw93KWvG4GfQDm3xch"></script>

	<!-- 地区插件 -->
	<script src="/public/js/distpicker.data.js"></script>	
	<script src="/public/js/distpicker.js"></script>
	<script src="/public/js/main.js"></script>	

	<script type="text/javascript" src="/public/js/jquery.cookie.js"></script>
	<script type="text/javascript" src="/public/js/base64.js"></script>
	<script type="text/javascript" src="/public/js/xiuzhen.js"></script>
	<script>
		if ($(document.body).width() < 760) {
			document.documentElement.style.fontSize = document.documentElement.clientWidth / 7.5 + 'px';
		} else {
			document.documentElement.style.fontSize = document.documentElement.clientWidth / 1 + 'px';
		}
	</script>
	<!--兼容ie8-->
	<!--[if lt IE 9]>
	    <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
	    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
	<!-- 头部导航开始 -->
	<div class="header">
		<div class="nav">
			<img class="logo" src="/public/images/logo.png" alt="">
			<ul class="top">
				<li>
					<a href="index.html">首页</a>
				</li>
				<li>
					<a href="box.html">图书展示</a>
				</li>
				<li>
					<a href="labOne.html">图书资讯</a>
					<!-- <ul class="child">
						<li>
							<a href="labOne.html">科学实验室1</a>
						</li>
						<li>
							<a href="labTwo.html">科学实验室2</a>
						</li>
						<li>
							<a href="labThree.html">科学实验室3</a>
						</li>
					</ul> -->
				</li>
				<!-- <li>
					<a href="maker.html">创客课程</a>
				</li> -->
				<li>
					<a href="about.html">关于我们</a>
				</li>
				<li>
					<a href="contact.html">联系我们</a>
				</li>
			</ul>
			<div class="right">
				<a href="login.html" class="login">会员登陆</a>
				
				<a class="indexCart" href="cart.html">
					<img class="cart" src="/public/images/cart.png" alt="">
				</a>
				<a class="leaguer" href="member.html" style="display: none;">
					<img class="" src="/public/images/people2.png" alt="">
				</a>
				<p id="username" style="display: none;"></p>
				<!-- <p class="line"></p>
				<img class="weixin" src="images/weixin.png" alt=""> -->
			</div>
		</div>
	</div>
	
	<!-- 购物车页面 -->
	<div class="cart confirm">
		<div class="container">
			<p class="title delivery">选择收货地址</p>
			<div class="receive">
				<div class="every first" style="display:none;">
					<p class="caption"></p>
					<p class="detailAdress"></p>
					<p class="phoneNumber"></p>
					<div>
						<img class="edit" src="/public/images/confirm3.png" alt="">
						<img class="checked" src="/public/images/confirm4.png" alt="">
					</div>
				</div>
				<div class="every special">
					<a href="address.html?comfirmTag=1">
						<img src="/public/images/confirm5.png" alt="">
					</a>
				</div>
			</div>
			<p class="title">确认订单信息</p>
			<div class="top">
				<div class="info">商品信息</div>
				<div class="price">单价（元）</div>
				<div class="num">数量</div>
				<div class="total">总价 ( 元 )</div>
				<div class="total">类型</div>
				<div class="total">小计</div>
			</div>
			<div class="content">
				
			</div>
			<div class="bottom">
				<div class="comFlef">
					<p></p>
					<p></p>
					<p></p>
				</div>
				<div class="comRight">
					<p class="comTotal">总计</p>
					<p class="grand"><span>0.00</span>元</p>
				</div>
			</div>
			<div class="submit">提交订单</div>
		</div>
	</div>
	<!-- 预约弹框样式 -->
	<div class="appointShadow"></div>


	<!-- 右侧弹框 -->
	<div class="rightFrame">
		<div class="bespoke"><a href="saleApply.html">代售申请</a></div>
		<div class="placement"><img src="/public/images/top.png" alt="">置顶</div>
	</div>

	<!-- 弹框样式 -->
	<div class="alert-box">
		<span class="xz-alert alert alert-danger"></span>
	</div>
	
	<!-- 公共底部开始 -->
	<div class="footer">
		<div class="footer-content1">
			<div></div>
		</div>
		<div class="footer-content">
			<div class="container">
				<div class="content">
					<div class="left">
						<img class="bottom-logo" src="/public/images/logo.png" alt="">
						<p class="des">此系统为不仅为人们提供了便利的购书平台，还在此基础上增加了代售和出租的功能，人们有想卖的书籍可以在此平台申请，平台会帮忙代售，还有的宝宝们，不想购买书籍，此平台提供了租书的功能，不需要购买就可以便宜看到自己想看的书籍啦！！！</p>
					</div>
					<div class="right">
						<div class="contact">
							<p class="title">联系我们</p>
							<p class="phone">电话：0755-23324516</p>
							<p class="email">邮箱：cd.01@oil-com.com</p>
							<p class="email">QQ：1056598469</p>
						</div>
					</div>
				</div>
				<p class="copy">地址：山西省太原市万柏林区下元街道公园时代城2号楼1301</p><br>
			</div>
		</div>	
		
	</div>

	

	<script type="text/javascript">
		


		if(!$.cookie('uid')){
			location.href = './index.html';
		}
		
		// 获取头部参数
		function parseUrl(url) {
			url = decodeURI(url)
			var splitURL = url.split('?')
			if (splitURL[0] == url) return {}
			var parmsStr = splitURL[1]
			var parms = parmsStr.split('&')
			var result = {}
			for (var i = 0; i < parms.length; i++) {
				var key = parms[i].split('=')[0]
				var value = Number(parms[i].split('=')[1]) || parms[i].split('=')[1]
				result[key] = value
			}
			return result
		}
		var commodityId =  parseUrl(window.location.href).commodityId;
		var typeArr = parseUrl(window.location.href).type;
		var type =  parseUrl(window.location.href).type;
		var addressId =  parseUrl(window.location.href).addressId;
		var cartTigs =  parseUrl(window.location.href).cartTigs;
		$.cookie('commodityId',commodityId,{path: '/'});
		$.cookie('type',type,{path: '/'});
		
		
		
		// 地址列表数据调用
		var adressIdArr = [];
		adressData();
		function adressData(){
			$.ajax({
                type: "get",
                dataType: "", // submit info
                url: url + '/v1/front/mall/address?userId=' + $.cookie('uid'),
                success: function (res) {
                    if (!res.resultStatus) {
                        $(".xz-alert").html(res.errorMessage);
                        $('.xz-alert').show();
                        setTimeout(function () {
                            $(".xz-alert").hide();
                        }, 3000);
                        return
					}
					var adressArr = res.resultData;
                    for (var i = 0; i < adressArr.length; i++) {
						adressIdArr.push(adressArr[i].addressId);		
					}
					for (var i = 0; i < adressIdArr.length; i++) {
						if(addressId == adressIdArr[i]){
							$.cookie('addressId',addressId,{path: '/'});
							break
						}
					}
					// 根据地址id获取收获地址的信息
					if($.cookie('addressId')){
						$(".confirm .every.first").css("display","block");
						$.ajax({
							type: "get",
							dataType: "", // submit info
							url: url + '/v1/front/mall/address/'+ $.cookie('addressId'),
							success: function (res) {
								if (!res.resultStatus) {
									$(".xz-alert").html(res.errorMessage);
									$('.xz-alert').show();
									setTimeout(function () {
										$(".xz-alert").hide();
									}, 3000);
									return
								}
								
								$(".caption").html(res.resultData.province + '' + res.resultData.city + '&nbsp;('+ res.resultData.reciverName +'&nbsp;收)')
								$(".detailAdress").html(res.resultData.district + '' + res.resultData.detailAddress);
								$(".phoneNumber").html(res.resultData.phoneNumber)
								$(".comFlef p:nth-child(1)").html("寄送至："+ res.resultData.province + '' + res.resultData.city + '' + res.resultData.district + '' + res.resultData.detailAddress);
								$(".comFlef p:nth-child(2)").html("收货人："+ res.resultData.reciverName);
								$(".comFlef p:nth-child(3)").html("联系电话："+ res.resultData.phoneNumber);	

								province = res.resultData.province;
								city = res.resultData.city;
								district = res.resultData.district;
								detailAddress = res.resultData.detailAddress;
								reciverName = res.resultData.reciverName;
								phoneNumber = res.resultData.phoneNumber;
								zipCode = res.resultData.zipCode;
							},
							error: function (e) {
								$(".xz-alert").html("请求数据失败");
								$('.xz-alert').show();
								setTimeout(function () {
									$(".xz-alert").hide();
								}, 3000);
							}
						})
					}
                },
                error: function (e) {
                    $(".xz-alert").html("请求数据失败");
                    $('.xz-alert').show();
                    setTimeout(function () {
                        $(".xz-alert").hide();
                    }, 3000);
                }
			})
			
		}

		
		var loginUrl = Base64.encode("confirm.html");  
		$('.header .nav .right .login').attr('href','./login.html?loginurl='+loginUrl); 

		var orderStatusTime;  //定时器
		var checkOrderStatus;  //订单号
		var orderAllPrice = 0;

		// 首页banner
		$('#bootstrap-touch-slider').bsTouchSlider();
		

		// 点击返回顶部
		$('.rightFrame .placement').on('click', function () {
			$("html,body").animate({
				scrollTop: 0
			}, 1000);
		});

		

		var province="";
		var city="";
		var district="";
		var detailAddress="";
		var reciverName="";
		var phoneNumber="";
		var zipCode = '';
		var commodityList = [];


		
		
		
		// 点击确认订单的编辑地址
		$(".confirm .every .edit").click(function(){
			location.href = './add_address.html?comfirmTag=1&addressId='+$.cookie('addressId');
		})

		// 当在商品详情页下单时获取商品的信息
		var price = 0;
		var optionValue = "";
		if(type=='111'){
			commodityList = JSON.parse(window.localStorage.commodityList);
			var shop="";
			var allMoney = 0;
			for(var i=0;i< commodityList.length;i++){
				shop += '<div class="item">'+
						'<div class="info">'+
						'<img src="'+ commodityList[i].simple +'" alt="">'+
						'<p class="">'+ commodityList[i].caption +'</p>'+
						'</div>'+
						'<div class="price">'+
						'<span>'+ commodityList[i].nowPrice +'</span>元'+
						'</div>'+
						'<div class="total">'+
						'<span>'+ commodityList[i].amounts +'</span>'+
						'</div>'+
						'<div class="total">'+
						'<span>'+ commodityList[i].nowPrice +'</span>元'+
						'</div>'+
						'<div class="total">'+
						''+ commodityList[i].type +''+
						'</div>'+
						'<div class="total money">'+
						'<span>'+ commodityList[i].nowPrice +'</span>元'+
						'</div></div>';
				allMoney += parseFloat(commodityList[i].price)		
			}
			$(".confirm .content").html(shop);
			$(".confirm .bottom .comRight .grand span").html(allMoney);
		}else{
			$.ajax({
				type: "get",
				dataType: "json", // submit info
				url: url + '/web/box/detail/' + $.cookie('commodityId'),
				success: function (res) {
					if (!res.resultStatus) {
						$(".xz-alert").html(res.errorMessage);
						$('.xz-alert').show();
						setTimeout(function () {
							$(".xz-alert").hide();
						}, 2000);
						return
					}

					var shop = '<div class="item">'+
								'<div class="info">'+
								'<img src="'+ res.resultData.bgPicture +'" alt="">'+
								'<p class="">'+ res.resultData.caption +'</p>'+
								'</div>'+
								'<div class="price">'+
								'<span>'+ res.resultData.nowPrice +'</span>元'+
								'</div>'+
								'<div class="total">'+
								'<span>1</span>'+
								'</div>'+
								'<div class="total">'+
								'<span>'+ res.resultData.nowPrice +'</span>元'+
								'</div>'+
								'<div class="total">'+
								''+ res.resultData.type +''+
								'</div>'+
								'<div class="total money">'+
								'<span>'+ res.resultData.nowPrice +'</span>元'+
								'</div></div>';
					$(".confirm .content").html(shop);
					price = res.resultData.nowPrice;
					var allMoney = 0;
					var moneyArr = $(".money span");
					
					for(var i=0;i< moneyArr.length;i++){
						allMoney += parseFloat(moneyArr[i].innerText)
					}
					$(".confirm .bottom .comRight .grand span").html(allMoney);
					
				},
				error: function (e) {
					$(".xz-alert").html("请求数据失败");
					$('.xz-alert').show();
					setTimeout(function () {
						$(".xz-alert").hide();
					}, 2000);
				}
		
			})
		}
		

		// 提交订单
		$(".confirm .submit").click(function(){
			commodityList = [
				{
					commodityId:$.cookie('commodityId'),
					amounts:1,
				}
			];
			confirm();	
		})

		// 提交订单公共函数
		function confirm(){
			if(province == ""){
				$(".xz-alert").html("请添加收获地址!");
				$('.xz-alert').show();
				setTimeout(function () {
					$(".xz-alert").hide();
				}, 2000);
			}else{
				$.ajax({
					type: "post",
					dataType: "json", // submit info
					url: url + '/v1/front/mall/order',
					data:{
						province:province,
						city:city,
						district:district,
						detailAddress:detailAddress,
						reciverName:reciverName,
						phoneNumber:phoneNumber,
						userId:$.cookie('uid'),
						commodityList:commodityList
					},
					contentType:"application/x-www-form-urlencoded",
					success: function (res) {
						if (!res.resultStatus) {
							$(".xz-alert").html(res.errorMessage);
							$('.xz-alert').show();
							setTimeout(function () {
								$(".xz-alert").hide();
							}, 2000);
							return
						}
						
						checkOrderStatus = res.resultData.orderNo;
						orderAllPrice = res.resultData.totalFee;
						
						$(".xz-alert").html("订单提交成功！");
						$('.xz-alert').show();
						setTimeout(function () {
							$(".xz-alert").hide();
							location.href = './order.html';
						}, 2000);
						
						
						

					},
					error: function (e) {
						$(".xz-alert").html("提交订单失败");
						$('.xz-alert').show();
						setTimeout(function () {
							$(".xz-alert").hide();
						}, 2000);
					}
			
				})
			}
	
		}

	
		
	</script>		

</body>

</html>